﻿/**
 * Peter
 * Created by: Peter Development Team
 *    http://peter.codeplex.com/
 * 
 * GNU General Public License version 2 (GPLv2)
 *    http://peter.codeplex.com/license
 *
 *  This code is provided on an AS IS basis, with no WARRANTIES,
 *  CONDITIONS or GUARANTEES of any kind.
 *  
 **/

using System.ComponentModel.Composition;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using Peter.Common;
using Peter.Common.BindingConverters;
using Peter.Common.Icons;
using Peter.Common.MainMenu;
using Peter.Common.Utilities;

namespace Peter.Ruby
{
   /// <summary>
   /// A tester for RSpec projects.
   /// </summary>
   public class RSpecTester
   {
      private CommandPrompt m_Cmd;
      private RelayCommand m_RunAllTests;
      
      /// <summary>
      /// Gets the commands to run all tests.
      /// </summary>
      public ICommand RunAllTests
      {
         get { return this.m_RunAllTests ?? (this.m_RunAllTests = new RelayCommand (this.OnRunAllTests)); }
      }

      /// <summary>
      /// Runs all the tests in the current project.
      /// </summary>
      /// <param name="obj">Command parameter.</param>
      private void OnRunAllTests (object obj)
      {
         if (this.m_Cmd == null)
         {
            this.m_Cmd = new CommandPrompt ();
            this.m_Cmd.Initialize ();
            this.m_Cmd.OutputRecieved += this.OnOutputReceived;
         }
      }

      private void OnOutputReceived (string message, bool iserror)
      {
      }

      /// <summary>
      /// Gets the run rspec tests menu item.
      /// </summary>
      [Export ("WorkspaceMenuItem")]
      public PeterContextMenuItem RunProjectTestsContextMenuItem
      {
         get
         {
            var item = new PeterContextMenuItem
            {
               Priority = 500,
               Header = "Run all RSpec tests",
               Icon = new IconDisplay { Icon = MainMenuIcon.Notestasks },
               Command = this.RunAllTests
            };
            item.CommandParameter = item.DataContext;
            item.SetBinding (UIElement.VisibilityProperty,
                             new Binding { Converter = new TypeVisibilityConverter<RailsProject> () });
            return item;
         }
      }
   }
}
